<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Kategori_model extends CI_Model
{
    
    function __construct()
    {
       parent::__construct();
		$this->CI = get_instance();
    }//end of function

    function cek_id_tgl(){        
        $id = mysql_insert_id();
        return $id;
    }

    function cek_kategori(){        
        $this->db->select('*');
        $this->db->from('HD_GENERAL_REF_D');
    }

    function insert_kategori($data){
        
        $this->db->insert('HD_GENERAL_REF_D',$data);
        
    }//end of function
    
    function update_kategori($id,$ket,$data){
        
        $this->db->where('ID_REF_DATA',$id);
        $this->db->where('KET_REF_DATA',$ket);
        $this->db->update('HD_GENERAL_REF_D',$data);        
        
    }//end of function
    
    function delete_kategori($data){
		
		$this->db->delete('HD_GENERAL_REF_D',$data);
	}

    function get_kategori(){
        
        $this->db->select('*');
        $this->db->from('HD_GENERAL_REF_D');
        //$this->db->where('STATUS > 0');
        $query = $this->db->get();
        return $query;        
        
    }//end of function

    function get_sub_by_jenis($id_ref_data){
        
        $this->db->select('*');
        $this->db->from('HD_GENERAL_REF_D');
        $this->db->where('ID_REF_DATA',$id_ref_data);
        $query = $this->db->get();
        return $query;        
        
    }//end of function

    function get_sub_by_name($ket_ref_data){
        
        $this->db->select('*');
        $this->db->from('HD_GENERAL_REF_D');
        $this->db->where('KET_REF_DATA',$ket_ref_data);
        $query = $this->db->get();
        return $query;        
        
    }//end of function

    function get_jns_by_ktg($ktg,$jns){
        
        $this->db->select('*');
        $this->db->from('HD_GENERAL_REF_D');
        $this->db->where('ID_REF_DATA',$ktg);
        $this->db->where('KET_REF_DATA',$jns);
        $query = $this->db->get();
        return $query;        
        
    }
    
	function get_id_kategori($id_kategori){
		$this->db->select('*');
		$this->db->from('HD_GENERAL_REF_D');
		$this->db->where('KODE',$id_kategori);
		$query = $this->db->get();
		return $query;
	}	

	function get_tahun_value($id_tahun){
		$this->db->select('TAHUN');
		$this->db->from('TAHUN');
		$this->db->where('IDTAHUN',$id_tahun);
		$query = $this->db->get();
		return $query;
	}
	
	function get_kategori_grid(){	
		$this->db->select('*');
		$this->db->from('HD_GENERAL_REF_D');
		//$this->db->where("STATUS > 0 ");
		$this->db->order_by("ID_REF_DATA", "asc"); 
		$this->CI->flexigrid->build_query();
		
		$return['records'] = $this->db->get();
		
		$this->db->select('*');
		$this->db->from('HD_GENERAL_REF_D');
		//$this->db->where("STATUS > 0 ");
		$this->CI->flexigrid->build_query(FALSE);
		
		$return['record_count'] = $this->db->count_all_results();

		return $return;
	}


		
}//end of class